#include "moduleadd.h"
#include <string.h>
#include <stdlib.h>

 char ret[8]={'\0'};
 char runret[32]={'\0'};

char*   getwsdl()
{
       // char * wsdl="hello";
	char * wsdl = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
		"<definitions xmlns:http=\"http://schemas.xmlsoap.org/wsdl/http/\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:s=\"http://www.w3.org/2001/XMLSchema\" xmlns:s0=\"http://tempuri.org/\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:tm=\"http://microsoft.com/wsdl/mime/textMatching/\" xmlns:mime=\"http://schemas.xmlsoap.org/wsdl/mime/\" targetNamespace=\"http://tempuri.org/\" xmlns=\"http://schemas.xmlsoap.org/wsdl/\">"
		"<types>"
		"<s:schema elementFormDefault=\"qualified\" targetNamespace=\"http://tempuri.org/\">"
		"<s:element name=\"run\">"
		"<s:complexType>"
		"<s:sequence>"
		"<s:element minOccurs=\"0\" maxOccurs=\"1\" name=\"cmd\" type=\"s:string\" />"
		"</s:sequence>"
		"</s:complexType>"
		"</s:element>"
		"<s:element name=\"runResponse\">"
		"<s:complexType>"
		"<s:sequence>"
		"<s:element minOccurs=\"0\" maxOccurs=\"1\" name=\"runResult\" type=\"s:string\" />"
		"</s:sequence>"
		"</s:complexType>"
		"</s:element>"
		"</s:schema>"
		"</types>"
		"<message name=\"runSoapIn\">"
		"<part name=\"parameters\" element=\"s0:run\" />"
		"</message>"
		"<message name=\"runSoapOut\">"
		"<part name=\"parameters\" element=\"s0:runResponse\" />"
		"</message>"
		"<portType name=\"webserivceClassSoap\">"
		"<operation name=\"run\">"
		"<input message=\"s0:runSoapIn\" />"
		"<output message=\"s0:runSoapOut\" />"
		"</operation>"
		"</portType>"
		"<binding name=\"webserivceClassSoap\" type=\"s0:webserivceClassSoap\">"
		"<soap:binding transport=\"http://schemas.xmlsoap.org/soap/http\" style=\"document\" />"
		"<operation name=\"run\">"
		"<soap:operation soapAction=\"http://tempuri.org/run\" style=\"document\" />"
		"<input>"
		"<soap:body use=\"literal\" />"
		"</input>"
		"<output>"
		"<soap:body use=\"literal\" />"
		"</output>"
		"</operation>"
		"</binding>"
		"<service name=\"webserivceClass\">"
		"<port name=\"webserivceClassSoap\" binding=\"s0:webserivceClassSoap\">"
		"<soap:address location=\"http://localhost:5001/database\" />"
		"</port>"
		"</service>"
		"</definitions>";
    return wsdl;
}
char * get_cmd(char * para)
{
//char *strstr(const char *haystack,const char *needle);
    char *p=strstr(para,"cmd");
    if(!p)
    {
        return NULL;
    }
    else 
        return p+sizeof("cmd");
}

char * get_para1(char * para)
{
    memset(ret,0,sizeof(ret));
    char * parahead=strstr(para,"op1=");
    ///char * p=NULL:
    if(!parahead)
    {
        return NULL;
    }
    else 
    {
        char * p=strchr(parahead+sizeof("op1="),';');
        if(!p)
        {
            return NULL;
        }
        else
        {
           
            char * head=NULL;
            int i=0;
            for(head=parahead;head!=p;head++)
            {
                
                ret[i]=*head;
                i++;
            }
            return ret;
        }
    }
      
}

char * get_para2(char * para)
{
    memset(ret,0,sizeof(ret));
    char * parahead=strstr(para,"op2=");
    if(!parahead)
    {
        return NULL;
    }
    else 
    {
        char * p=strchr(parahead+sizeof("op2="),';');
        if(!p)
        {
            return NULL;
        }
        else
        {
         
            char * head=NULL;
            int i=0;
            for(head=parahead;head!=p;head++)
            {
                
                ret[i]=*head;
                i++;
            }
            return ret;
        }
    }
      
}


char *  run(char*  name,char * para)
{
   // char *p="run";
   // return p;
    char * cmd=get_cmd( para);
    int intret=0;
    int a=get_para1(para);
    int b=get_para2(para);
    if(strcmp(cmd,"add")==0)
    {
        intret= a+b;
        sprintf(runret,"%d",intret);
        return runret;
    }
    else 
    {
        return NULL;
    }
}
